package com.service.component.role.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.service.component.common.CommonResult;
import com.service.component.role.entity.Role;
import com.service.component.role.mapper.RoleMapper;
import com.service.component.role.services.RoleServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Calvin
 * @create ：2021/7/22 14:12
 * @description：角色服务实现
 * @modified By：
 * @version: 1.0.0$
 */
@Service
public class RoleServiceImpl implements RoleServices {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public CommonResult insertRole(Role role) {
        int insert = roleMapper.insert(role);
        return insert > 0 ? CommonResult.success() : CommonResult.commonResult(CommonResult.ResultCode.REQUEST_SQL_ERROR);
    }

    @Override
    public List<Role> getRoleByUserId(String userId) {
        return roleMapper.getRoleByUserId(userId);
    }

    @Override
    public Role getRoleByPermName(String roleName) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("ROLE_NAME_EN",roleName);
        return roleMapper.selectOne(queryWrapper);
    }
}
